package com.hand.demo.api.controller.v2;

import com.hand.demo.app.service.ExampleService;
import com.hand.demo.config.SwaggerTags;
import com.hand.demo.domain.entity.Example;
import com.hand.demo.domain.repository.ExampleRepository;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hzero.core.util.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = SwaggerTags.EXAMPLE)
@RestController("exampleController.v2")
@RequestMapping("/v2/example")
public class ExampleController {

    @Autowired
    private ExampleService exampleService;

    @Autowired
    private ExampleRepository exampleRepository;

//    @ApiOperation(value = "根据ID获取")
//    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", paramType = "path")
//    })
//    @GetMapping("/{id}")
//    public ResponseEntity<Example> hello(@PathVariable Long id) {
//        return Results.success(exampleRepository.selectByPrimaryKey(id));
//    }


    @ApiOperation(value = "初始化测试")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", paramType = "path")
//    })
    @GetMapping("/test")
    public ResponseEntity<String> test() {
        try {
            return Results.success("test success");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }


    @ApiOperation(value = "初始化测试2")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
    @GetMapping("/test2")
    public ResponseEntity<String> test2() {
        return Results.success("test success 2");
    }

    @ApiOperation(value = "初始化测试3")
    @Permission(level = ResourceLevel.SITE, permissionLogin = true)
    @GetMapping("/test3")
    public ResponseEntity<List<Example>> test3() {
        return Results.success(exampleRepository.queryAllExampleList());
    }
}
